package com.ruoyi.douyin.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.douyin.service.open.UserOpenDataService;
import com.ruoyi.douyin.vo.UserOpenDataVideoDataVo;
import com.ruoyi.system.domain.DouyinUser;
import com.ruoyi.system.service.DouyinUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/douyin/user")
public class DouyinUserController {
    @Autowired
    private DouyinUserService douyinUserService;
    @Autowired
    private UserOpenDataService userOpenDataService;

    @GetMapping("info")
    public AjaxResult findUserById(String id) {
        DouyinUser douyinUser = douyinUserService.findUserById(id);
        return AjaxResult.success(douyinUser);
    }

    @GetMapping("/getDouyinUserList/{index}")
    public AjaxResult getDouyinUserList(@PathVariable int index) {
//        ArrayList<DouyinUser> douyinUsers = new ArrayList<>();
        PageHelper.startPage(index, 10);
        List<DouyinUser> list = douyinUserService.getDouyinUserList();
//        for (DouyinUser douyinUser : list) {
//            Long id = douyinUser.getId();
//            DouyinUser douyin = douyinUserService.findUserById(String.valueOf(id));
//            String openId = douyin.getOpenId();
//            douyinUser.setOpenId(openId);
//            douyinUsers.add(douyinUser);
//        }
        return AjaxResult.success(PageInfo.of(list));
    }

    @GetMapping("/getDouyinUserListDESC")
    public AjaxResult getDouyinUserListDESC() {
        List<DouyinUser> list = douyinUserService.getDouyinUserListDESC();
        return AjaxResult.success(list);
    }
}
